#!/usr/bin/env python3
"""
URL过滤功能演示
"""
import sys
import os
from datetime import datetime

sys.path.insert(0, os.path.dirname(__file__))

from idea_proxy import IDEAProxy
from simple_dashboard_fixed import SimpleDashboard

# 创建代理实例
proxy = IDEAProxy('127.0.0.1', 8080)

# 添加丰富的测试数据
test_requests = [
    {
        'timestamp': datetime.now().isoformat(),
        'client_addr': '127.0.0.1:12345',
        'method_line': 'GET https://plugins.jetbrains.com/api/plugins HTTP/1.1',
        'headers': {'User-Agent': 'IntelliJ IDEA/2023.3', 'Host': 'plugins.jetbrains.com'},
        'raw_request': 'GET https://plugins.jetbrains.com/api/plugins HTTP/1.1'
    },
    {
        'timestamp': datetime.now().isoformat(),
        'client_addr': '127.0.0.1:12346',
        'method_line': 'CONNECT plugins.jetbrains.com:443 HTTP/1.1',
        'headers': {'User-Agent': 'IntelliJ IDEA/2023.3', 'Host': 'plugins.jetbrains.com'},
        'raw_request': 'CONNECT plugins.jetbrains.com:443 HTTP/1.1'
    },
    {
        'timestamp': datetime.now().isoformat(),
        'client_addr': '127.0.0.1:12347',
        'method_line': 'GET https://api.github.com/user HTTP/1.1',
        'headers': {'User-Agent': 'git/2.39.0', 'Host': 'api.github.com'},
        'raw_request': 'GET https://api.github.com/user HTTP/1.1'
    },
    {
        'timestamp': datetime.now().isoformat(),
        'client_addr': '127.0.0.1:12348',
        'method_line': 'POST https://httpbin.org/post HTTP/1.1',
        'headers': {'User-Agent': 'curl/7.68.0', 'Host': 'httpbin.org'},
        'raw_request': 'POST https://httpbin.org/post HTTP/1.1'
    },
    {
        'timestamp': datetime.now().isoformat(),
        'client_addr': '127.0.0.1:12349',
        'method_line': 'GET https://maven.apache.org/repository/index.html HTTP/1.1',
        'headers': {'User-Agent': 'Maven/3.8.1', 'Host': 'maven.apache.org'},
        'raw_request': 'GET https://maven.apache.org/repository/index.html HTTP/1.1'
    }
]

for req in test_requests:
    proxy.requests_log.append(req)

print("🎯 URL过滤功能演示")
print("=" * 60)
print("✅ 已添加测试数据，包含多种不同类型的URL")
print("🔍 现在可以使用URL过滤功能进行模糊匹配过滤")
print()
print("📋 测试建议:")
print("   - 输入 'jetbrains' 过滤JetBrains相关请求")
print("   - 输入 'api' 过滤API端点")
print("   - 输入 'github' 过滤GitHub请求")
print("   - 输入 'maven' 过滤Maven请求")
print()

# 启动dashboard
dashboard = SimpleDashboard(proxy, 8084)
dashboard.start()

print("🚀 URL过滤演示Dashboard已启动!")
print("🌐 请访问浏览器测试过滤功能")
print()
print("⏹️  程序将在后台运行，按Ctrl+C停止")

try:
    import time
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    print("\n⏹️  正在停止Dashboard...")
    dashboard.stop()
    print("✅ Dashboard已停止")
    print("🎉 URL过滤功能演示完成！")